package com.tencet.servlet;

import com.alibaba.druid.support.json.JSONUtils;
import com.tencet.dao.TransferDAO;
import com.tencet.dao.impl.TransferDAOImpl;
import com.tencet.entity.AccountOne;
import com.tencet.service.AccountOneService;
import com.tencet.service.AccountTwoService;
import com.tencet.service.Impl.AccountOneServiceImpl;
import com.tencet.service.Impl.AccountTwoServiceImpl;
import com.tencet.service.Impl.TransferServiceImpl;
import com.tencet.service.TransferService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author: @date: 2022/7/21 21:41
 * @description:
 */
@WebServlet("/transfer2")
public class TransferServlet2 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String card2_num = (String)req.getSession().getAttribute("secondAccountNumber");
        System.out.println(card2_num + "二类卡号");

        AccountTwoService accountTwoService = new AccountTwoServiceImpl();
        String id = accountTwoService.getId(card2_num);
        AccountOneService accountOneService = new AccountOneServiceImpl();
        java.util.List<AccountOne> list = accountOneService.getAccountOneList(id);


        req.getSession().setAttribute("accountList",list);

//        List list1 = new ArrayList<>();
//        for (int i = 0; i < list.size(); i++) {
//            list1.add(list.get(i));
//        }
//        req.getSession().setAttribute("list1",list1);
        List<String > card_num = new ArrayList();
        for (int i = 0; i < list.size(); i++) {
            card_num.add(list.get(i).getCard_num());
        }
//        List card_num = ww.getCard_num(phone);
        String s = JSONUtils.toJSONString(card_num);
        resp.getWriter().write(""+s);
    }
}